#!/usr/sbin/rsct/perl5/bin/perl 
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 1999,2002 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# "@(#)47   1.15   src/rsct/registry/cli/bin/mvsr.perl, srcli, rsct_rpyxh, rpyxht1f3 2/22/01 16:25:50"
######################################################################
#                                                                    #
# Module: mvsr                                                       #
#                                                                    #
# Purpose:                                                           #
#   mvsr - Moves directories and tables (entries) in the System      #
#          Registry.                                                 #
#                                                                    #
# Syntax:                                                            #
#   To move one or more tables or directories to a directory:        #
#   mvsr [-h][-f][-TV] Source_entry ... Target_directory             #
#                                                                    #
#   To rename a directory or table:                                  #
#   mvsr [-h][-f][-TV] Source_entry Target_entry                     #
#                                                                    #
# Flags:                                                             #
#   -h  Help. Writes this command's usage statement to stdout.       #
#   -f  Force. Does not prompt you before overwriting an existing    #
#       entry.                                                       #
#   -T  Trace. Writes this command's trace messages to stderr.       #
#   -V  Verbose. Writes this command's verbose messages to stderr.   #
#                                                                    #
# Operands:                                                          #
#   Source_entry    The Source_entry can be either a relative or     #
#           absolute path name for a table or directory. If you are  #
#           using mvsr to rename the source_entry, more than one     #
#           Source_entry can be specified ONLY when the Target_entry #
#           is a directory. The path for the Target_entry must exits #
#           in the System Registry.                                  #
#   Target_directory    The name of the directory to be moved to.    #
#           The Target_directory must be a relative or absolute path #
#           name that already exists in the System Registry.         #
#   Target_entry    The Target_entry can be either a relative or     #
#           absolute path name for a directory or table. If you are  #
#           moving a directory the Target_entry must be a directory. #
#           If you are using mvsr to rename the Source_entry then the#
#           Target_entry must be of the same type as the Source_entry#
#                                                                    #
# Description:                                                       #
#   The mvsr command can be used to move a directory or table to     #
#   another parent directory or to rename a table or directory.      #
#                                                                    #
#   More than one Source_entry can be moved if the target is an      #
#   existing directory. If more than one source is specifiied it is  #
#   equivalent to the command being invoked once for each source.    #
#   An attempt will be made to move all the sources listed, with     #
#   errors reported for unsuccessful calls.                          #
#                                                                    #
#   If the target entry exists, you will be prompted to overwrite    #
#   unles the [-f] flag is specified to force the operation.         #
#                                                                    #
#   When you move a directory into an existing directory, the        #
#   directory and its contents are added under the existing          #
#   directory unless the -f flag is used. In this case the target    #
#   directory and it's subtree are deleted before the move is made.  #
#                                                                    #
#   The moved entry inherits the storage characteristics of it's new #
#   parent directory.                                                #
#                                                                    #
#   Use the lssr -R command to get a recursive list of the current   #
#   System Registry directory structure.                             #
#                                                                    #
# Exit Values:                                                       #
#   0  SR_CLI_SUCCESS        Command completed successfully.         #
#   1  SR_CLI_REGISTRY_ERROR Command terminated due to an underlying #
#                            System Registry error.                  #
#   2  SR_CLI_ERROR          Command terminated due to an underlying #
#                            error in the command script.            #
#   3  SR_CLI_BAD_OPERAND    Command terminated due to user          #
#                            specifying a bad operand.               #
#   4  SR_CLI_BAD_FLAG       Command terminated due to user          #
#                            specifying an invalid flag.             #
#   5  SR_CLI_USER_ERROR     Command terminated due to a user error. #
#                            For example specifying an undefined     #
#                            directory to be listed.                 #
# Examples:                                                          #
#   Assumption: the CT_SR_HOME environment variable is set to        #
#   /samples in the cases where an absolute path name is used in the #
#   examples.                                                        #
#                                                                    #
#   1. To move table Host to a new name Host.bak (rename), where the #
#   target does not already exist in the System Registry, enter:     #
#       mvsr Host Host.bak                                           #
#                                                                    #
#   2. To move table Host to the existing directory backup,          #
#   automatically overwriting an existing copy of the target, enter: #
#       mvsr -f Host backup/Host                                     #
#                                                                    #
#   3. To move directory test to the directory /tmp/test, enter:     #
#   automatically overwriting an existing copy of the target, enter: #
#       mvsr test /tmp/test  ost                                     #
#                                                                    #
#   To change a data value in a row in /samples/People where the     #
#   data field contains spaces:                                      #
#   chsrfld /samples/People ID==20 State="North Dakota"              #
#                                                                    #
#   To change a data value in a row in /samples/tabel1 where the     #
#   data uses resource handles:                                      #
#   chsrfld /samples/table1 Name=Mum PetalID="0x12345678 0xabcdefab  #
#      0x00000000 0x00000000 0x00000000"                             #
#                                                                    #
#--------------------------------------------------------------------#
# Inputs:                                                            #
#                                                                    #
# Outputs:                                                           #
#   stdout - help/usage statement                                    #
#   stderr - trace, verbose and error messages                       #
#                                                                    #
# External Ref:                                                      #
#   Commands: $LMSGS                                                 #
#   Extensions:  CT::SR.pm CT::SRrc.pm CT::CT.pm                     #
#   Perl library routines: Getopts::Std                              #
#   SR cli routines: : SR_cli_utils.pm - init_session, isRelative    #
#                                    term_session, printCEMsg        #
#                      SR_cli_rc.pm - CLI return codes               #
#                                                                    #
# Tab Settings:                                                      #
#   4 and tabs should be expanded to spaces before saving this file. #
#   in vi:  (:set ts=4  and   :%!expand -4)                          #
#                                                                    #
# Change Activity:                                                   #
#   000900 HGJ 38317: Initial delivery.                              #
#                                                                    #
######################################################################

#--------------------------------------------------------------------#
#                                                                    #
# General Program Flow/Logic:                                        #
#                                                                    #
# A: Parse command line - get table name and other flags, operands   #
# B: Initialise session with registry, including changing the        #
#    current directory if a relative path name is given (use value   #
#    given in CT_SR_HOME)                                            #
# C: For each source entry, call CT::SR::move_entry to attempt the   #
#    move                                                            #
# D: Close session table and tree                                    #
#                                                                    #
#--------------------------------------------------------------------#


#--------------------------------------------------------------------#
# Included libraries and extensions                                  #
#--------------------------------------------------------------------#
use lib "/usr/sbin/rsct/pm";
use locale;
use Getopt::Std;
use FileHandle;

use CT::CT qw(:ct_data_type_t);
use CT_cli_utils qw(printIMsg
                    printEMsg
);

use CT::SRrc;
use CT::SR;
use CT::SR qw(:sr_qualifier_t);
use SR_cli_utils qw(init_session isRelative 
                    term_session printCEMsg 
                    printCIMsg  $DEFAULT_GLOBAL_MOUNT_POINT
                    error_exit  set_session_variables
); 
use SR_cli_rc qw(:return_codes);


#--------------------------------------------------------------------#
# Global Variables                                                   #
#--------------------------------------------------------------------#
# Global constant values 
$TRUE           = 1;
$FALSE          = 0;

# Other variables
$Verbose        = $FALSE;               # -V flag : see ($opt_V)
$Trace          = $FALSE;               # -T flag : see ($opt_T)
$Opt_Overwrite  = $FALSE;               # -f flag : see ($opt_f)

# Messaging variables
$PROGNAME       = "mvsr";               # Program Name for messages
$MSGCAT         = "srcli.cat";          # msg catalogue for this cmd
$CTDIR          = "/usr/sbin/rsct";     # Cluster directory path
$CTBINDIR       = "$CTDIR/bin";         # Cluster Bin directory path
$LSMSG          = "$CTBINDIR/ctdspmsg"; # Display message routine
$ENV{'MSGMAPPATH'} = "$CTDIR/msgmaps";  # Msg map path for $LSMSG  

%Cleanup = ();                          # Hash of items to cleanup
                                        # {Session} $session to term

#--------------------------------------------------------------------#
# Variables                                                          #
#--------------------------------------------------------------------#
# Variables for use with extensions
my $Tree_handle    = "";                # initialised in init_session

# Other variables
my @Source_entry   = ();                # list of source entries
my @Source         = ();                # fully qualified source(s)
my $Target_entry   = "";                # target of move
my $Target         = "";                # fully qualified target
my $Set_work_dir   = $FALSE;            # flag whether to set SR CWD
my $Overwrite      = $FALSE;            # Used to toggle overwrite arg
my $redo           = $FALSE;            # redo a move if overwrite

my $Mount_point    = $DEFAULT_GLOBAL_MOUNT_POINT;

my $rc             = 0;                 # assume good return code
my $badrc          = 0;                 # assume good return code


#--------------------------------------------------------------------#
# Main Code                                                          #
#--------------------------------------------------------------------#
# TODO: Many verbose statements in this code will eventually by
# Trace statements when the facility is available as a Perl CLI
# (feature 48401)
# TODO: security on access to the table can not be further defined
# until after a security design has been implemented for the SR.
# ( feature 48402 ) Until then, the table is opened with the
# minimum security necessary to complete the command.
# TODO: FFDC handling will be implemented in Feature 48397.
# TODO: NLS handling will be implemented in Feature 48395


# Parse the command line, exit if there are errors
# Error messages handled in parse_cmd_line
($rc, $Target_entry, @Source_entry) = parse_cmd_line();
($rc == 0) || error_exit($rc);  

if ($Verbose) {
    foreach (@Source_entry) {
        $Column_list .= "  ".$_."\n";
    }
    $Command_line_input = "\"  $Column_list\n  $Target_entry\n\"";
    printIMsg("IMsgmvsrCommandLineInput", $Command_line_input);
}


# Initialize variables for init_session - check to see if an
# absolute or relative entry name has been passed in.
# Prepare each entry with the full mount point or not, 
# depending on whether it was a relative entry or absolute.

($Set_work_dir, $Target) = set_session_variables($Target_entry);

$ind = 0;
foreach (@Source_entry) {
    ($holder, $Source[$ind++]) = set_session_variables($_);
    if ($holder == $TRUE) {$Set_work_dir = $TRUE;}
}


# Initialize Registry Library Connection
# Error messages handled in init_session
($rc,$Tree_handle) = init_session($Set_work_dir);
($rc == 0) || error_exit($rc);  

# Add the session tree to the cleanup hash
$Cleanup{Session} = $Tree_handle;


# Check the moves for logic, and report errors as necessary
# Error messages handled in check_moves
$Trace && print STDERR "Entering check_moves\n";
($rc, $Target_type) = 
        check_moves($Tree_handle, $Target, @Source);
$Trace && print STDERR "check_moves return code $rc\n";
($rc == 0) || error_exit($rc);  



# Attempt to move each source given to the target

$ind = 0;
foreach $source (@Source) {

    if ($Target_entry eq $Source_entry[$ind]) {
        printCEMsg("EMsgSRcliIdenticalEntries", 
                        $Target_entry, $Source_entry[$ind]);   
        $rc = SR_CLI_BAD_OPERAND;
        next;   
    }   

    # If more than one source is defined, the correct name must
    # be used for messages and prompts
    my $entry = "";

    if ($Target_type eq 'dir') {

        # Create the correct target name based on the entries given.
        # Absolute names are used in the command, but this is for 
        # messages and prompting.
        $entry = $Target_entry.'/'. strip_name($Target_entry, $Source_entry[$ind]);
    }
    else { $entry = $Target_entry; }
  

    # Set overwrite switch based on a flag request or command line 
    # input
    $Overwrite = $TRUE if ($redo or $Opt_Overwrite);

 
    $Verbose && 
        printIMsg("IMsgmvsrMovingEntry", $Source_entry[$ind], $entry,
                        $Overwrite);

    $Trace && print STDERR "Calling CT::SR::move_entry($source, $Target, $Overwrite)\n";

    # Call the extension 
    $rc = CT::SR::move_entry($Tree_handle, $source, $Target, 
                        $Overwrite);

    $Trace && print STDERR "CT::SR::move_entry return code $rc\n";

    $redo = $FALSE if $redo;
    if ($rc == SR_ENTRY_EXISTS) {
        # Prompt and redo this attempt if requested
        printIMsg("IMsgmvsrOverwrite", $entry);

        # Read from STDIN one line. As long as it begins
        # with a 'y' or 'Y', redo the last move
        # TODO: investigate using LC_MESSAGES in here
        # where NLS feature is being implemented

        $fh = new FileHandle "-";
        $answer = $fh->getline;
        $fh->close;

        if (($answer =~ /^y/) or ($answer =~ /^Y/)) { 
            $redo = $TRUE;
            $answer = "";
            redo; 
            $rc = 0;
        }
    }
    $rc = error_check("sr_move_entry", $rc, $Source_entry[$ind], 
        $entry);
    # Continue if anything but a severe registry error
    ($rc == SR_CLI_REGISTRY_ERROR) && error_exit($rc);

    # Save the first bad return code 
    if ($rc != 0 && $badrc == 0) { $badrc = $rc; }

    $ind++;


} # end foreach $source (@Source)

# Checking badrc here because different categories of error could
# exists based on multiple user errors allowed on the command line.
($badrc == 0) || error_exit($badrc);

# Clean session before quitting
$rc = term_session($Tree_handle, $Mount_point);

exit $rc;

#--------------------------------------------------------------------#
# End Main Code                                                      #
#--------------------------------------------------------------------#


#--------------------------------------------------------------------#
# check_moves:                                                       #
#   Checks the move commands given for logic. Checks for:            #
#   - greater than one source sent to a table target                 #
#   - greater than one source sent to a non-existing target (assumes #
#   it is a table and returns an error)                              #
#   - source directory being copied to table target                  #
#   All the above cases return an error code of SR_CLI_BAD_OPERAND.  #
#                                                                    #
# Parameters:                                                        #
#   $target_entry - the target entry to be compared with             #
#   @source - array of source entry names to be checked against targ.#
#                                                                    #
# Return values:                                                     #
#   $local_rc - 0 unless one of the checks matches                   #
#   $target_type - type of the target entry for later use            #
#                                                                    #
# Global variables modified:                                         #
#   $Trace             output   True (-T) turn Trace mode on.        #
#   $Verbose           output   True (-V) turn Verbose mode on.      #
#--------------------------------------------------------------------#
sub check_moves
{
my ($tree_handle, $target, @source) = @_;

# Set up local variables
my $target_type = 'none';
my $source_type = 'none';
my $local_rc = 0;

my $display_target = $target;
$display_target =~ s /^$DEFAULT_GLOBAL_MOUNT_POINT//;

# Check the Target type first

($local_rc, $target_type) = get_entry_type($target, $tree_handle);

# Error messages handled in get_entry_type
$local_rc and return $local_rc;


if ($Verbose) {
    if ($target_type eq 'dir') {
        printCIMsg("IMsgSRcliDirTarget", $display_target); 
    }
    else { 
        printCIMsg("IMsgSRcliTableTarget", $display_target); 
    }
}

# Like AIX cp, if there are multiple tables given to be copied
# to a single table, burp out the usage statement and quit

if (($target_type eq 'table') and ($#source > 0)) {
    print_usage();
    return SR_CLI_BAD_OPERAND;
}


# If the target entry does not exist and multiple entries are given 
# to move, print the Usage statement and exit 

if (($target_type eq 'none') and ($#source > 0)) {
    print_usage();
    return SR_CLI_BAD_OPERAND;
}


# Check each source type against the target type.
# If an attempt is made to copy a directory to a table, the 
# command stops

foreach (@source) {

    ($local_rc, $source_type) = 
                    get_entry_type($_, $tree_handle);

    # Strip off any existing leading '/SR' for display purposes
    $display_source = $_;
    $display_source  =~ s /^$DEFAULT_GLOBAL_MOUNT_POINT//;

    if ($Verbose) {
        if ($source_type eq 'dir') {
            printCIMsg("IMsgSRcliDirSource", $display_source); 
        }
        else { 
            printCIMsg("IMsgSRcliTableSource", $display_source); 
        }
    }

    if (($target_type eq 'table') and ($source_type eq 'dir')) {
        printEMsg("EMsgmvsrTableToDir", $display_source, 
                                $display_target);
        return SR_CLI_BAD_OPERAND;
    }

}

return $local_rc, $target_type;
}   # end check_moves


#--------------------------------------------------------------------#
# strip_name:                                                        #
#   if the target_entry and source have a common directory path,     #
#   the source is stripped of this path so a correct source path     #
#   can be constructed for messaging and prompting purposes.         #
#                                                                    #
# Parameters:                                                        #
#   $target_entry - the target entry to be compared with             #
#   $source - the source entry name to be compared and stripped      #
#                                                                    #
# Return values:                                                     #
#   $source - the stripped source value.                             #
#                                                                    #
#--------------------------------------------------------------------#
sub strip_name
{
my ($target_entry, $source)  = @_;
my $target = $target_entry;

my $equal = 1;

while (($target =~ /\//) and $equal) {
    $dir = $target;
    $dir =~ s/^(.*)\/.*/$1/;
    $target =~ s/^.*\/(.*)/$1/;
    if (!($source =~ s/^$dir//)) { $equal = 0; }

}

# Strip off any leading '/' so a relative entry is given back
$source =~ s/^\///;

return $source;
}   # end strip_name


#--------------------------------------------------------------------#
# get_entry_type:                                                    #
#   Uses CT::SR::is_in_directory to verify if the target exists, and #
#   if it does to return the entry type.                             #
#                                                                    #
# Parameters:                                                        #
#   $target - the target entry to be worked on                       #
#   $tree - valid tree handle for the library session                #
#                                                                    #
# Return values:                                                     #
#   $local_rc - local return code                                    #
#   $type - '', 'none', 'table', 'dir', depending on outcome of      #
#    the CT::SR::is_in_directory call                                #
#                                                                    #
# Global variables used:                                             #
#   None.                                                            #
#--------------------------------------------------------------------#
sub get_entry_type
{

# Have to include this for properly checking the target type if
# a relative target has been used.
use Env qw(CT_SR_HOME);
use CT::SR qw(:sr_entry_t);

# Grab input parameters
my ($target, $tree) = @_;

# Set up local variables
my ($parent_dir, $entry);
my $type = 0;
my $storage = 0;
my $local_rc = 0;

$main::Trace && print STDERR "Entered get_entry_type($target)\n";

# Strip off /SR for use in any possible messaging
# (value is internal to the CLI.)
#$temp_dir = $directory;
#$temp_dir =~ s/^$DEFAULT_GLOBAL_MOUNT_POINT//;


# If it is a relative directory, put the entire path together
#if (isRelative($target)) { $target = '/SR'.$CT_SR_HOME.'/'.$target; }
if (isRelative($target)) { 
    $target = "$DEFAULT_GLOBAL_MOUNT_POINT".$CT_SR_HOME.'/'.$target; 
}


# Split off the right most entry in the current directory so
# there is a parent directory and entry to pass to 
# CT::SR:is_in_directory

if ($target =~ /\//) {
    $parent_dir = $target;
    $parent_dir =~ s/(.*)\/.*$/$1/;

    $entry = $target;
    $entry =~ s/.*\/(.*)$/$1/;
}
else {
    $parent_dir = '/SR';
    $entry = $target;
}

$Trace && print STDERR "Calling CT::SR::is_in_directory($parent_dir, $entry)\n";
$local_rc = CT::SR::is_in_directory($tree, $parent_dir, $entry, 
                        $type, $storage);
$Trace && 
    print STDERR "CT::SR::is_in_directory return code: $local_rc\n";

if ($local_rc != 0) {
    if (($local_rc == SR_NO_DIRECTORY) or ($local_rc == SR_NO_ENTRY)){

        # Entry is new, so can simply keep going without a type
        $local_rc = 0;
        $type = 'none';
    }
    elsif ($local_rc == SR_NO_PERMISSION) {
        printEMsg("EMsgmvsrNoPermissionTarget", $target);
        return SR_CLI_USER_ERROR;
    }
    else {
        printEMsg("EMsgSRcliErrorValidatingTarget");
        printCEMsg("EMsgSRcliSRCommandFailure", 
                            "sr_is_in_directory", $local_rc);
        $local_rc = SR_CLI_REGISTRY_ERROR;
    }
    return $local_rc, $type;
}

# Verify that the entry checked is not a table
# If it is an unknown type, is considered a severe Registry Error

if ($type == SR_TABLE){
    $type = 'table';
}
elsif ($type == SR_DIRECTORY){
    $type = 'dir';
}
elsif ($type == SR_UNKNOWN_ENTRY) {

    $Verbose && print STDERR "Entry type is $type\n";
    printEMsg("EMsgmvsrUnknownEntry", $type);
    $local_rc = SR_CLI_REGISTRY_ERROR;

}

$main::Trace && 
    print STDERR "Leaving get_entry_type($local_rc, $type)\n";
return $local_rc, $type;
}   # get_entry_type


#--------------------------------------------------------------------#
# parse_cmd_line:                                                    #
#   Parses the command line for options and operands.                #
#   Set appropriate global variables as outlined below, make sure we #
#   have a valid combination of arguments / options.                 #
#                                                                    #
# Return values:                                                     #
#   $local_rc - local return code                                    #
#   $target_name - name of target directory or entry.                #
#   @ARGV        - one or more source entries.                       #
#                                                                    #
# Global variables modified:                                         #
#   $Opt_Overwrite     output   True (-f) turns overwrite on.        #
#   $Trace             output   True (-T) turn Trace mode on.        #
#   $Verbose           output   True (-V) turn Verbose mode on.      #
#--------------------------------------------------------------------#
sub parse_cmd_line
{
my $local_rc = 0;
my @columns = ();
my $table_name = "";
my $count = 0;
my %opts = ();

if (getopts('hfTV', \%opts) == 0) {         # Parse input flags
    printCEMsg("EMsgSRcliInvalidFlag");
    print_usage();
    return SR_CLI_BAD_FLAG;
}                  

# Print usage and exit if -h used
if (defined $opts{h}) {   
    print_usage();
    exit(0);    
}

# Set Trace flag if requested
if (defined $opts{T}) {
    $Trace = $TRUE;
}

# Set Verbose flag if requested
if (defined $opts{V}) {
    $Verbose = $TRUE;
}

# Set $Opt_Overwrite flag if requested
if (defined $opts{f}) {
    $Opt_Overwrite = $TRUE;
}

# Do a basic check on the count of arguments
if (scalar(@ARGV) < 2) {
    printCEMsg("EMsgSRcliMissingOperands");
    print_usage();
    return SR_CLI_BAD_OPERAND;
}

# Get target entry name from input.
# mvsr [-hfTV] Source_entry... Target_directory
# mvsr [-hfTV] Source_entry Target_entry
# pop the last entry of @ARGV, assuming this is the table name
$target_name = pop @ARGV;

# Assign the Source entries back to the arg list via @ARGV
return ($local_rc, $target_name, @ARGV);
}   # end parse_cmd_line


#--------------------------------------------------------------------#
# error_check:                                                       #
#   Checks the return code from the SR function.  If an error is     #
#   detected appropriate error messages will be displayed and        #
#   SR CLI return code set.                                          #
#                                                                    #
# Parameters:                                                        #
#   $sr_function  - Name of the SR function that was called and      #
#                   whose error code we are checking.                #
#   $sr_rc        - SR function return code.                         #
#   $source_entry - a specific source entry.                         #
#   $entry        - the target entry.                                #
#   $table_name   - Name of the table trying to create.              #
#                                                                    #
# Return values:                                                     #
#   None.                                                            #
#                                                                    #
# Global References:                                                 #
#   None.                                                            #
#--------------------------------------------------------------------#
sub error_check
{
my ($sr_function, $sr_rc, $source_entry, $entry) = @_;
my $rc = 0;

if ($sr_rc != 0) {
    if ($sr_rc == SR_CONNECTION_LOST) {
        printCEMsg("EMsgSRcliConnectionLost");
        $rc = SR_CLI_REGISTRY_ERROR;
    }
# TODO: Defect 71605, registry component, only returning 
# SR_NO_PERMISSION not the .._SOURCE or .._TARGET
# Also in ct_sr_rc.h they are defined as SR_NO_PERMISSION_TA
# or SR_NO_PERMISSION_SO
    elsif ($sr_rc == SR_NO_PERMISSION) {
        printEMsg("EMsgmvsrNoPermissionSource", $source_entry);
        printEMsg("EMsgmvsrNoPermissionTarget", $entry);
        $rc = SR_CLI_USER_ERROR;
    }
#   elsif ($sr_rc == SR_NO_PERMISSION_SOURCE) {
#       printEMsg("EMsgmvsrNoPermissionSource", $source_entry);
#       $rc = SR_CLI_USER_ERROR;
#   }
#   elsif ($sr_rc == SR_NO_PERMISSION_TARGET) {
#       printEMsg("EMsgmvsrNoPermissionTarget", $entry);
#       $rc = SR_CLI_USER_ERROR;
#   }
    elsif ($sr_rc == SR_NO_DIRECTORY) {
        printEMsg("EMsgSRcliNoDirectory", $entry);
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_ILLEGAL_OPERATION) {
        printEMsg("EMsgmvsrIllegalOp");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_NO_ENTRY) {
        printEMsg("EMsgmvsrNoEntry", $source_entry);
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_INVALID_OVERWRITE) {
        printEMsg("EMsgmvsrInvalidOverwrite");
        $rc = SR_CLI_ERROR;
    }
    elsif ($sr_rc == SR_ENTRY_EXISTS) {
        printEMsg("EMsgmvsrEntryExists", $entry);
        $rc = SR_CLI_USER_ERROR;
    }
    else {
        printEMsg("EMsgmvsrErrorMovingEntry", $source_entry, $entry);
        printCEMsg("EMsgSRcliSRCommandFailure", $sr_function, $sr_rc);
        $rc = SR_CLI_REGISTRY_ERROR;
    }
}   

return ($rc);
}   # end error_check


#--------------------------------------------------------------------#
# print_usage : print the usage statement (syntax) to stdout.        #
#   See this command's prologue syntax section for current usage.    #
#--------------------------------------------------------------------#
sub print_usage
{
printIMsg("IMsgmvsrUsage");
}   # end print_usage


#--------------------------------------------------------------------#
# End File                                                           #
#--------------------------------------------------------------------#
